import axios from 'axios'

// 导入 nprogress 包对应的 JS 和 CSS
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

export const baseURL = 'http://127.0.0.1:8000/'
const instance = axios.create({
  baseURL
})

instance.interceptors.request.use(config => {
  NProgress.start()

  if (config.url.includes('/like') || config.url.includes('/comment')) {
    const tokenStr = window.localStorage.getItem('token')
    config.headers.Token = tokenStr
  }

  return config
})

instance.interceptors.response.use(config => {
  NProgress.done()
  return config
})

export default instance
